package com.mdd.admin.controller.course;

import com.mdd.admin.config.aop.Log;
import com.mdd.admin.service.course.ICourseCatalogueService;
import com.mdd.admin.validate.course.CourseCatalogueParam;
import com.mdd.admin.validate.common.PageParam;
import com.mdd.admin.validate.course.CourseColumnParam;
import com.mdd.admin.validate.course.CourseParam;
import com.mdd.admin.vo.course.CourseCatalogueListVo;
import com.mdd.admin.vo.course.CourseCatalogueDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 课程目录管理
 * @author panweiliang
 */
@RestController
@RequestMapping("api/course/catalogue")
public class CourseCatalogueController {

    @Resource
    ICourseCatalogueService iCourseCatalogueService;

    /**
     * 课程目录列表
     *
     * @author panweiliang
     * @param pageParam 分页参数
     * @param params 搜索参数
     * @return Object
     */
    @GetMapping("/list")
    public Object list(@Validated PageParam pageParam,
                       @RequestParam(value  = "courseId") Integer courseId,
                       @RequestParam Map<String, String> params) {
        PageResult<CourseCatalogueListVo> list = iCourseCatalogueService.list(courseId, pageParam, params);
        return AjaxResult.success(list);
    }
    /**
     * 课程目录详情
     *
     * @author panweiliang
     * @param id 主键ID
     * @return Object
     */
    @GetMapping("/detail")
    public Object detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        CourseCatalogueDetailVo detail = iCourseCatalogueService.detail(id);
        return AjaxResult.success(detail);
    }

    /**
     * 课程目录新增
     *
     * @author panweiliang
     * @param courseCatalogueParam 参数
     * @return Object
     */
    @Log(title = "课程目录新增")
    @PostMapping("/add")
    public Object add(@Validated(value = CourseCatalogueParam.create.class) @RequestBody CourseCatalogueParam courseCatalogueParam) {
        iCourseCatalogueService.add(courseCatalogueParam);
        return AjaxResult.success();
    }

    /**
     * 课程目录编辑
     *
     * @author panweiliang
     * @param courseCatalogueParam 参数
     * @return Object
     */
    @Log(title = "课程目录编辑")
    @PostMapping("/edit")
    public Object edit(@Validated(value = CourseCatalogueParam.update.class) @RequestBody CourseCatalogueParam courseCatalogueParam) {
        iCourseCatalogueService.edit(courseCatalogueParam);
        return AjaxResult.success();
    }

    /**
     * 课程目录删除
     *
     * @author panweiliang
     * @param courseCatalogueParam 参数
     * @return Object
     */
    @Log(title = "课程目录删除")
    @PostMapping("/del")
    public Object del(@Validated(value = CourseCatalogueParam.delete.class) @RequestBody CourseCatalogueParam courseCatalogueParam) {
        iCourseCatalogueService.del(courseCatalogueParam.getId());
        return AjaxResult.success();
    }

    /**
     * 课程目录状态
     *
     * @author panweiliang
     * @param courseCatalogueParam 课程目录参数
     * @return AjaxResult
     */
    @Log(title = "课程目录上下架状态")
    @PostMapping("/change")
    public AjaxResult change(@Validated(value = CourseCatalogueParam.change.class)
                             @RequestBody CourseCatalogueParam courseCatalogueParam) {
        return AjaxResult.success(iCourseCatalogueService.changeStatus(courseCatalogueParam.getId()));
    }


    /**
     * 切换课程目录收费方式
     *
     * @author panweiliang
     * @param courseCatalogueParam 课程目录参数
     * @return AjaxResult
     */
    @Log(title = "专栏目录收费方式")
    @PostMapping("/feeType/change")
    public AjaxResult changeFeeType(@Validated(value = CourseCatalogueParam.change.class)
                                          @RequestBody CourseCatalogueParam courseCatalogueParam) {
        return AjaxResult.success(iCourseCatalogueService.changeFeeType(courseCatalogueParam.getId()));
    }

}
